package com.zgyd.util;

import jakarta.annotation.PostConstruct;
import org.springframework.ai.document.Document;
import org.springframework.ai.reader.JsonReader;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class MyJsonReader {

    @Autowired
    private VectorStore vectorStore;

	private final Resource resource;

    MyJsonReader(@Value("classpath:guize.json") Resource resource) {
        this.resource = resource;
    }

    @PostConstruct
	List<Document> loadJsonAsDocuments() {
        JsonReader jsonReader = new JsonReader(this.resource, "description", "condition","type","id");
        vectorStore.add(jsonReader.get());
        return jsonReader.get();
	}
}